"""
roc_auc_score
"""
import numpy as np
from sklearn.metrics import roc_auc_score, roc_curve, auc


def get_data():
    """

    :return:
    """
    y_true = np.array([0, 0, 1, 1])
    y_pred = np.array([0.1, 0.4, 0.35, 0.8])
    return y_true, y_pred


def compute_roc_scores(y_true, y_pred):
    """

    :param y_true:
    :param y_scores:
    :return:
    """
    if len(np.unique(y_true)) != 2:
        raise Exception('Only one class present in y_true. ROC AUC score '
                        'is not defined in that case.')
    # FP率，TP率
    fpr, tpr, tresholds = roc_curve(y_true=y_true, y_score=y_pred)
    return auc(fpr, tpr)


def run():
    """
    主程序
    :return:
    """
    y_true, y_pred = get_data()

    # 自己算
    my_roc_auc = compute_roc_scores(y_true=y_true, y_pred=y_pred)

    roc_auc = roc_auc_score(y_true=y_true, y_score=y_pred)

    print('my: {}, sklean: {}'.format(my_roc_auc, roc_auc))


if __name__ == '__main__':
    run()
